package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
public class CalcController {

    @RequestMapping("/add")
    // 这里的路由要和 calc.html 中的 <form action="/add"> 相同
    public String calc(Integer num1, Integer num2) {
        if (num1 == null || num2 == null)
            return "参数有误!";
        return num1 + " + " + num2 + " = " + (num1 + num2);
        // url: http://localhost:8080/calc.html  (访问页面).
    }
}
